//入口文件；
import React, {Component} from "react";
import {Provider} from "mobx-react/native";
import {
  AppRegistry,
  View,
  Text,
  Animated,
  StyleSheet,
} from 'react-native';
import App from "./src";
import NetInfoDecorator from "./src/common/NetInfoDecorator";

//判断是否是开发模式；
if(!__DEV__) {
	global.console = {
		log: () => {},
	}
}
@NetInfoDecorator
export default class Root extends Component {
	constructor(props) {
		super(props);
		this.state = {
			slideDown: new Animated.Value(0),
		};
	}
	componentWillReceiveProps(nextProps) {
		const {isConnected} = nextProps;
		//无网络；
		if(!isConnected) {
			Animated.timing(
				this.state.slideDown,
				{
					toValue: 1,
					duration: 200,
				}
			).start(() => {
				setTimeout(() => {
					Animated.timing(
						this.state.slideDown,
						{
							toValue: 0,
							duration: 200,
						}
					).start()
				}, 2000);
			})
		}
	}	
	render() {
		let positionY = this.state.slideDown.interpolate({
			inputRange: [0, 1],
			outputRange: [-35, __IOS__ ? 20 : 0]
		});
		return (
			<View style={{flex: 1}}>
				<Animated.View
					style={[{top: positionY}, styles.netInfoView]}
				>
					<Text style={[styles.netInfoText,]}>网络异常，请检查网络稍后重试~</Text>
				</Animated.View>
				<Provider>
					<App /> 
				</Provider>
			</View>
		);
	}
} 

const styles = StyleSheet.create({
	netInfoView: {
		height: 35,
		justifyContent: "center",
		alignItems: "center",
		position: "absolute",
		left: 0,
		right: 0,
		backgroundColor: gColor.backgroundWarnView,
	},
	netInfoText: {
		color: "#F2F2F2",
	}
})

AppRegistry.registerComponent('yyj', () => Root);